﻿
using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;

namespace BTKERP.DAL
{
	#region UserDAL
	public class UserDAL : DBContext
	{
		public List<User> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UsersSelectAll");
            return GetEntityList<User>(cmd);
        }

        public User GetById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UserSelect");
            cmd.AddParameter("@Id", id);
            return GetSingleEntity<User>(cmd);
        }

		public List<User> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UserSelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<User>(cmd);
        } 
		
        public bool DeleteById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UserDelete");
            cmd.AddParameter("@Id", id);
            return ExecuteCommand(cmd);
        }

        public User UpdateById(
		Guid paramUserID,

		string paramName,

		string paramPassword,

		string paramDisplayName,

		Guid paramRoleID,

		int paramStatus,

		string paramUpdatedBy,
		DateTime paramUpdateOn
			)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_UserUpdate");
			cmd.AddParameter("@UserID", paramUserID);
			cmd.AddParameter("@Name", paramName);
			cmd.AddParameter("@Password", paramPassword);
			cmd.AddParameter("@DisplayName", paramDisplayName);
			cmd.AddParameter("@RoleID", paramRoleID);
			cmd.AddParameter("@Status", paramStatus);
			cmd.AddParameter("@UpdatedBy", paramUpdatedBy);
            cmd.AddParameter("@UpdatedOn", DateTime.Now);
            return GetSingleEntity<User>(cmd);
        }


        public User UserLogin(string username, string password)
        {
            ExSQLCommand cmd = new ExSQLCommand("cust_user_login");
            cmd.AddParameter("@username", username);
            cmd.AddParameter("@password", password);
            return GetSingleEntity<User>(cmd);
        }
    }
	#endregion
}
